package com.sunlands.zlcx.usercenter.repository;

import com.sunlands.zlcx.usercenter.domain.UserDayLearnDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface UserDayLearnRepository extends JpaRepository<UserDayLearnDO, Long>, JpaSpecificationExecutor<UserDayLearnDO> {

   @Query(value = "select * from tz_user_day_learn where user_id = ?1 and year_months = ?2 order by year_months_day asc", nativeQuery = true)
   List<UserDayLearnDO> findByUserIdAndYearMonthsOrderByYearMonthsDayASC(Integer userId, String yearMonths);

   @Query(value = "select * from tz_user_day_learn where user_id = ?1 and year_months_day = ?2", nativeQuery = true)
   UserDayLearnDO findByUserIdAndYearMonthsDay(Long userId, String yearMonthsDay);

   @Query(value = "select sum(study_minutes) from tz_user_day_learn where user_id = ?1 and ?2  < year_months_day ", nativeQuery = true)
   Integer findUserDayLearnTime(Long userId, String data);

   List<UserDayLearnDO> findByYearMonthsDayAndUserIdIn(String date, List<Long> friendIdList);

   @Query(value = "select sum(lianmai_minutes) from tz_user_day_learn where user_id = ?1 ", nativeQuery = true)
   Integer sumLianmaiMinutes(Long userId);
}

